﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Word_Learner_3.Web;


namespace Word_Learner_3.Model
{
    class Word
    {
        private string catagory;
        public Word(string catagory)
        {
            this.catagory = catagory;
        }

        private string key;

        public string Key
        {
            get { return key; }
            set { key = value; }
        }
        private string phono;

        public string Phono
        {
            get { return phono; }
            set { phono = value; }
        }
        private string trans;

        public string Trans
        {
            get { return trans; }
            set { trans = value; }
        }
        private string example;

        public string Example
        {
            get { return example; }
            set { example = value; }
        }
        private Word getWord(DataRow dr)
        {
            Word word = new Word(catagory);
            word.Key = dr["Key"].ToString();
            word.Phono = dr["Phono"].ToString();
            word.Trans = dr["Trans"].ToString();
            word.Example = dr["Example"].ToString();

            return word;
        }
        public List<Word> getWords()
        {
            List<Word> wordList = new List<Word>();
            DataSet ds = DBHelper.ExecuteDataset("select * from "+catagory);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                wordList.Add(getWord(ds.Tables[0].Rows[i]));

            }
            return wordList;

        }
    }
}
